import 'dart:collection';
import 'dart:convert';
import 'dart:io';

import 'package:changxindianzishangwu/cache/local_cache.dart';
import 'package:changxindianzishangwu/dao/collect_dao.dart';
import 'package:changxindianzishangwu/dao/common_language_dao.dart';
import 'package:changxindianzishangwu/dao/emoji_list_dao.dart';
import 'package:changxindianzishangwu/dao/save_some_message_dao.dart';
import 'package:changxindianzishangwu/else/lib/common/index.dart';
import 'package:changxindianzishangwu/model/address_book_model.dart';
import 'package:changxindianzishangwu/model/collect_list_model.dart';
import 'package:changxindianzishangwu/model/common_language_model.dart';
import 'package:changxindianzishangwu/pages/message/message_icon_page.dart';
import 'package:changxindianzishangwu/provider/currentMessageList.dart';
import 'package:changxindianzishangwu/util/colors.dart';
import 'package:changxindianzishangwu/util/toast.dart';
import 'package:changxindianzishangwu/widget/get_contacts_widget.dart';
import 'package:emoji_picker_flutter/emoji_picker_flutter.dart';
import 'package:flutter/material.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'package:flutter_plugin_record/flutter_plugin_record.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:image_picker/image_picker.dart';
import 'package:path_provider/path_provider.dart';
import 'package:permission_handler/permission_handler.dart';
import 'package:provider/provider.dart';
import 'package:tencent_im_sdk_plugin/models/v2_tim_message.dart';
import 'package:tencent_im_sdk_plugin/models/v2_tim_value_callback.dart';
import 'package:tencent_im_sdk_plugin/tencent_im_sdk_plugin.dart';
import 'package:video_player/video_player.dart';
import 'package:video_thumbnail/video_thumbnail.dart';
import 'package:wechat_assets_picker/wechat_assets_picker.dart';

import '../collect_page.dart';
import 'common_language_page.dart';

class SendMessageAllPage extends StatefulWidget {
  List<AddressBookModel> someUser;
  SendMessageAllPage({Key key, this.someUser}) : super(key: key);

  @override
  _SendMessageAllPageState createState() => _SendMessageAllPageState();
}

class _SendMessageAllPageState extends State<SendMessageAllPage> {
  /// 文本组件控制器
  TextEditingController _textEditingController = TextEditingController();

  /// 临时目录
  String _tempPath;
  String bottomIcon = "images/message/表情.png";
  final _focusNode = FocusNode();
  bool flag = false;
  String names;
  FlutterPluginRecord recordPlugin = new FlutterPluginRecord();
  bool soundFlag = false;
  String filePath = "";
  int soundDur = 0;
  bool flags = false;
  bool flagVoices = false;
  bool flagVoices2 = false;
  final List<String> actions = [
    '复制',
    '转发',
    '收藏',
    '删除',
    '多选',
  ];
  List leftSpots = [];
  OverlayEntry overlayEntry;
  String voiceIco = "images/voice_volume_1.png";
  @override
  void initState() {
    super.initState();
    //getDataList();
    getNames();
    _loadUserInfo();
    _initRecordMp3();

    _loadTempPath();

    //logi();
    _focusNode.addListener(() {
      print("Has focus: ${_focusNode.hasFocus}");
      if (_focusNode.hasFocus) {
        setState(() {
          bottomIcon = "images/message/键盘.png";
          favorite = true;
          flag = false;
          emojo = true;
        });
      } else {
        setState(() {
          bottomIcon = "images/message/表情.png";
        });
      }
    });

    ///初始化方法的监听
    recordPlugin.responseFromInit.listen((data) {
      if (data) {
        print("初始化成功");
      } else {
        print("初始化失败");
      }
    });
    getData();

    /// 开始录制或结束录制的监听
    recordPlugin.response.listen((data) async {
      if (data.msg == "onStop") {
        ///结束录制时会返回录制文件的地址方便上传服务器
        print("onStop  文件路径" +
            data.path
                .replaceRange(data.path.length - 3, data.path.length, "mp3"));
        filePath = data.path;
        print("onStop  时长 " + data.audioTimeLength.toString());
        soundDur = int.parse(data.audioTimeLength
            .toString()
            .substring(0, data.audioTimeLength.toString().indexOf(".")));
        await _soundSelect();
      } else if (data.msg == "onStart") {
        print("onStart --");
      } else {
        print("--" + data.msg);
      }
    });

    recordPlugin.responseFromAmplitude.listen((data) {
      var voiceData = double.parse(data.msg);
      setState(() {
        if (voiceData > 0 && voiceData < 0.1) {
          voiceIco = "images/voice_volume_2.png";
        } else if (voiceData > 0.2 && voiceData < 0.3) {
          voiceIco = "images/voice_volume_3.png";
        } else if (voiceData > 0.3 && voiceData < 0.4) {
          voiceIco = "images/voice_volume_4.png";
        } else if (voiceData > 0.4 && voiceData < 0.5) {
          voiceIco = "images/voice_volume_5.png";
        } else if (voiceData > 0.5 && voiceData < 0.6) {
          voiceIco = "images/voice_volume_6.png";
        } else if (voiceData > 0.6 && voiceData < 0.7) {
          voiceIco = "images/voice_volume_7.png";
        } else if (voiceData > 0.7 && voiceData < 1) {
          voiceIco = "images/voice_volume_7.png";
        } else {
          voiceIco = "images/voice_volume_1.png";
        }
        if (overlayEntry != null) {
          overlayEntry.markNeedsBuild();
        }
      });

      print("振幅大小   " + voiceData.toString() + "  " + voiceIco);
    });
    recordPlugin.responsePlayStateController.listen((data) {
      print("播放路径   " + data.playPath);
      print("播放状态   " + data.playState);
    });
  }

  ///初始化语音录制的方法
  void _initRecordMp3() async {
    recordPlugin.init();
  }

  void _requestAppDocumentsDirectory() {
//    if(Platform.isIOS){
//      //ios相关代码
//      setState(() {
//        getApplicationDocumentsDirectory().then((value) {
//          String nowDataTimeStr = DateUtil.getNowDateMs().toString();
//          String wavPath = value.path + "/" + nowDataTimeStr + ".wav";
//          startByWavPath(wavPath);
//        });
//      });
//    }else if(Platform.isAndroid){
//      //android相关代码
//    }

    setState(() {
      getApplicationDocumentsDirectory().then((value) {
        String nowDataTimeStr = DateUtil.getNowDateMs().toString();
        // TODO  注意IOS 传递的Mp3路径一定是以 .MP3 结尾
        String wavPath = "";
        if (Platform.isIOS) {
          wavPath = value.path + "/" + nowDataTimeStr + ".wav";
        } else {
          wavPath = value.path + "/" + nowDataTimeStr;
        }
        startByWavPath(wavPath);
      });
    });
  }

  ///开始语音录制的方法
  void start() async {
    recordPlugin.start();
  }

  ///根据传递的路径进行语音录制
  void startByWavPath(String wavPath) async {
    recordPlugin.startByWavPath(wavPath);
  }

  ///停止语音录制的方法
  void stop() {
    recordPlugin.stop();
  }

  ///播放语音的方法
  void play() {
    recordPlugin.play();
  }

  ///播放指定路径录音文件  url为iOS播放网络语音，file为播放本地语音文件
  void playByPath(String path, String type) {
    recordPlugin.playByPath(path, type);
  }

  ///暂停|继续播放
  void pause() {
    recordPlugin.pausePlay();
  }

  void stopPlay() {
    recordPlugin.stopPlay();
  }

  @override
  void dispose() {
    super.dispose();
    stopPlay();
    recordPlugin.dispose();
    EasyLoading.dismiss();
    String text = _textEditingController.text.trim();
  }

  /// 加载连目录
  _loadTempPath() async {
    _tempPath = (await getTemporaryDirectory()).path;
    this.setState(() {});
  }

  buildOverLayView(BuildContext context) {
    if (overlayEntry == null) {
      overlayEntry = new OverlayEntry(builder: (content) {
        return Positioned(
          top: MediaQuery.of(context).size.height * 0.5 - 80,
          left: MediaQuery.of(context).size.width * 0.5 - 80,
          child: Material(
            type: MaterialType.transparency,
            child: Center(
              child: Opacity(
                opacity: 0.8,
                child: Container(
                  width: 160,
                  height: 160,
                  decoration: BoxDecoration(
                    color: Color(0xff77797A),
                    borderRadius: BorderRadius.all(Radius.circular(20.0)),
                  ),
                  child: Column(
                    children: <Widget>[
                      Container(
                        margin: EdgeInsets.only(top: 10),
                        child: new Image.asset(
                          voiceIco,
                          width: 100,
                          height: 100,
                          package: 'flutter_plugin_record',
                        ),
                      ),
                      Container(
//                      padding: EdgeInsets.only(right: 20, left: 20, top: 0),
                        child: Text(
                          "手指上滑,取消发送",
                          style: TextStyle(
                            fontStyle: FontStyle.normal,
                            color: Colors.white,
                            fontSize: 14,
                          ),
                        ),
                      )
                    ],
                  ),
                ),
              ),
            ),
          ),
        );
      });
      Overlay.of(context).insert(overlayEntry);
    }
  }

  bool isRecording = false;
  bool isSend = true;
  String conversationID;

  //   // List<MessageEntity> messages = await (_conversation.groupID != null
  //   //     ? TencentImPlugin.getGroupHistoryMessageList(
  //   //         groupID: _conversation.groupID, count: 100)
  //   //     : TencentImPlugin.getC2CHistoryMessageList(
  //   //         userID: _conversation.userID, count: 100));
  //   // this.setState(() {
  //   //   this._messages = messages;
  //   // });
  //
  //   // 下载语音、视频缩略图
  //   for (var item in messages) {
  //     if (item.elemType == MessageElemTypeEnum.Video) {
  //       File file = new File(
  //           _tempPath + "/" + (item.node as VideoMessageNode).snapshotUuid);
  //       print("object下载视频音频：：：：：" + file.path.toString());
  //       if (!file.existsSync()) {
  //         TencentImPlugin.downloadVideoThumbnail(
  //                 message: FindMessageEntity(msgId: item.msgID),
  //                 path: file.path)
  //             .then((value) {
  //           this.setState(() {});
  //         });
  //       }
  //     }
  //
  //     if (item.elemType == MessageElemTypeEnum.Sound) {
  //       File file =
  //           new File(_tempPath + "/" + (item.node as SoundMessageNode).uuid);
  //       if (!file.existsSync()) {
  //         TencentImPlugin.downloadSound(
  //                 message: FindMessageEntity(msgId: item.msgID),
  //                 path: file.path)
  //             .then((value) {
  //           this.setState(() {});
  //         });
  //       }
  //     }
  //   }
  //
  //   this.setState(() {});
  // }

//   /// 发送按钮点击事件
//   _onSend() async {
//     String text = _textEditingController.text;
//     if (text.trim() == '') {
//       return;
//     }
//     this._sendMessage(TextMessageNode(content: text, atUserList: []));
//     _textEditingController.text = "";
//   }
//
  _imagesSelect() async {
    File file;
    int c = 0;
    await _handleCameraAndMic();
    final List<AssetEntity> assets = await AssetPicker.pickAssets(context);
    if (assets.isEmpty) {
      return;
    }
    StringBuffer sps = new StringBuffer();
    List<String> fileList = [];
    assets.forEach((element) async {
      file = await element.originFile;
      userId = [];
      int i = 0;

      bool x = false;
      EasyLoading.showToast("发送中...");
      widget.someUser.forEach((element) async {
        V2TimValueCallback<V2TimMessage> res = await TencentImSDKPlugin
            .v2TIMManager
            .getMessageManager()
            .sendImageMessage(
              imagePath: file.path,
              receiver: element.userId,
            );
        List<V2TimMessage> list = new List.empty(growable: true);
        userId.add(element.userId);
        if (res.code == 0) {
          fileList.add(json.encode({
            "TImages": res.data.imageElem.imageList[0].url,
            "XImages": res.data.imageElem.imageList[1].url,
            "OImages": res.data.imageElem.imageList[2].url,
          }));
          V2TimMessage msg = res.data;
          list.add(msg);
          Provider.of<CurrentMessageListModel>(context, listen: false)
              .addMessage("c2c_" + element.userId, list);
          i++;
          if (i == widget.someUser.length) {
            print(widget.someUser.length);
            x = true;
            if (x) {
              sps = new StringBuffer("");
              userId.toSet().toList().forEach((element) {
                sps.write(element + ",");
                print("====================>>>>>>>>>" + element);
              });

              fileList.forEach((element) {
                print("======here::::" + element);
              });
              c++;
              if (c == assets.length) {
                var result = await SaveSomeMessageDao.saveSomeMessage(
                    context: '',
                    contextType: 10,
                    receiver: widget.someUser.length,
                    toUsers: sps,
                    fileinfoString: fileList.toSet().toList(),
                    userId: userIdS);
                if (result['resultCode'] == 1) {
                  EasyLoading.dismiss();
                  toast("发送成功");
                  sps = new StringBuffer();
                  userId = [];
                  Get.back(result: 'true');
                } else {
                  EasyLoading.dismiss();
                  toast("发送成功");
                  sps = new StringBuffer();
                  userId = [];

                  toast("保存失败");
                }
              }
            }
          }
        } else {
          EasyLoading.dismiss();
          showToast("发送失败～");
        }
      });
    });

    // this._sendMessage(ImageMessageNode(path: pickedFile.path));
  }

  _videoSelect() async {
    _handleCameraAndMic();
    final pickedFile =
        await ImagePicker().getVideo(source: ImageSource.gallery);
    if (pickedFile == null) return;

    // 获得视频缩略图
    String thumb = await VideoThumbnail.thumbnailFile(
      video: pickedFile.path,
      thumbnailPath: _tempPath,
      imageFormat: ImageFormat.JPEG,
      quality: 40,
    );

    // 获得控制器并获得视频时长
    VideoPlayerController playerController =
        VideoPlayerController.file(File(pickedFile.path));
    await playerController.initialize();
    int duration = playerController.value.duration.inSeconds;

    print("视频路径" + pickedFile.path);
    userId = [];
    int i = 0;
    bool x = false;
    EasyLoading.showToast("发送视频中..");
    widget.someUser.forEach((element) async {
      V2TimValueCallback<V2TimMessage> res = await TencentImSDKPlugin
          .v2TIMManager
          .getMessageManager()
          .sendVideoMessage(
              videoFilePath: pickedFile.path,
              receiver: element.userId,
              duration: duration,
              type: "mp4",
              snapshotPath: thumb);

      List<V2TimMessage> list = new List.empty(growable: true);
      userId.add(element.userId);
      if (res.code == 0) {
        V2TimMessage msg = res.data;
        list.add(msg);
        Provider.of<CurrentMessageListModel>(context, listen: false)
            .addMessage("c2c_" + element.userId, list);
        i++;
        if (i == widget.someUser.length) {
          print(widget.someUser.length);
          x = true;
          if (x) {
            StringBuffer sp = new StringBuffer();
            userId.forEach((element) {
              sp.write(element + ",");
            });
            var result = await SaveSomeMessageDao.saveSomeMessage(
                context: res.data.videoElem.videoUrl,
                contextType: 4,
                OImages: res.data.videoElem.snapshotUrl,
                receiver: widget.someUser.length,
                toUsers: sp,
                userId: userIdS);
            if (result['resultCode'] == 1) {
              EasyLoading.dismiss();
              toast("发送成功");
              Get.back(result: 'true');
            } else {
              EasyLoading.dismiss();
              toast("发送成功");
            }
          }
        }
      } else {
        EasyLoading.dismiss();

        showToast("发送视频失败");
      }
    });
  }

  _photoSelect() async {
    final pickedFile = await ImagePicker().getImage(source: ImageSource.camera);
    if (pickedFile == null) return;
    userId = [];
    int i = 0;
    bool x = false;
    EasyLoading.showToast("发送图片中..");
    widget.someUser.forEach((element) async {
      V2TimValueCallback<V2TimMessage> res = await TencentImSDKPlugin
          .v2TIMManager
          .getMessageManager()
          .sendImageMessage(
            imagePath: pickedFile.path,
            receiver: element.userId,
          );
      List<V2TimMessage> list = new List.empty(growable: true);
      userId.add(element.userId);
      if (res.code == 0) {
        V2TimMessage msg = res.data;
        list.add(msg);

        Provider.of<CurrentMessageListModel>(context, listen: false)
            .addMessage("c2c_" + element.userId, list);

        i++;
        if (i == widget.someUser.length) {
          print(widget.someUser.length);
          x = true;
          if (x) {
            StringBuffer sp = new StringBuffer();
            userId.forEach((element) {
              sp.write(element + ",");
            });
            var result = await SaveSomeMessageDao.saveSomeMessage(
                context: res.data.imageElem.imageList[0].url,
                contextType: 3,
                receiver: widget.someUser.length,
                toUsers: sp,
                userId: userIdS);
            if (result['resultCode'] == 1) {
              EasyLoading.dismiss();
              toast("发送成功");
              Get.back(result: 'true');
            } else {
              EasyLoading.dismiss();
              toast("发送成功");
            }
          }
        }
        ;
      } else {
        EasyLoading.dismiss();
        showToast("发送图片失败");
      }
    });

    // this._sendMessage(ImageMessageNode(path: pickedFile.path));
  }

  _soundSelect() async {
    if (flags) {
      if (filePath == null) return;
      userId = [];
      EasyLoading.showToast("发送中..");
      V2TimMessage data;
      V2TimValueCallback<V2TimMessage> res;
      int i = 0;
      bool x = false;
      widget.someUser.forEach((element) async {
        res = await TencentImSDKPlugin.v2TIMManager
            .getMessageManager()
            .sendSoundMessage(
              soundPath: filePath,
              receiver: element.userId,
              duration: soundDur,
            );
        userId.add(element.userId);
        data = res.data;
        List<V2TimMessage> list = new List.empty(growable: true);
        V2TimMessage msg = res.data;
        if (res.code == 0) {
          list.add(msg);
          Provider.of<CurrentMessageListModel>(context, listen: false)
              .addMessage("c2c_" + element.userId, list);
          i++;
          if (i == widget.someUser.length) {
            print(widget.someUser.length);
            x = true;
            if (x) {
              StringBuffer sp = new StringBuffer();
              userId.forEach((element) {
                sp.write(element + ",");
              });
              var result = await SaveSomeMessageDao.saveSomeMessage(
                  context: data.soundElem.url,
                  contextType: 2,
                  length: data.soundElem.duration,
                  receiver: widget.someUser.length,
                  toUsers: sp,
                  userId: userIdS);
              if (result['resultCode'] == 1) {
                EasyLoading.dismiss();
                toast("发送成功");
                Get.back(result: 'true');
              } else {
                EasyLoading.dismiss();
                toast("发送成功");
              }
            }
          }
        }
        EasyLoading.dismiss();
        toast("发送成功");
      });
    }
  }

  _handleCameraAndMic() async {
    //申请权限

    bool a = await Permission.photos.request().isGranted;
    print(a);
    if (a == true) {
      print(a);
      print("已经打开");
    } else {
      showToast("请打开图库权限");
      await Future.delayed(Duration(seconds: 1));
      print(a);
      openAppSettings();
    }

//
  }

  List<String> userId;

  /// 发送消息
  _sendMessage(value) async {
    if (value == null || value == "".trim()) {
      return showToast("不能发送空消息");
    }
    userId = [];
    V2TimValueCallback<V2TimMessage> res;
    _textEditingController.text = "";
    EasyLoading.show(status: "发送的消息为:  ${value}");
    widget.someUser.forEach((element) async {
      userId.add(element.userId);
      res = await TencentImSDKPlugin.v2TIMManager
          .getMessageManager()
          .sendTextMessage(
            text: value,
            receiver: element.userId,
          );
      print("commint!!!!!!!!!!!!!!!!!!!!!!!!");
      print(res.data.toJson());

      if (res.code == 0) {
        EasyLoading.dismiss();

        // _messages.insert(_messages.length, res.data);
        List<V2TimMessage> list = new List.empty(growable: true);
        V2TimMessage msg = res.data;
        list.add(msg);
        Provider.of<CurrentMessageListModel>(context, listen: false)
            .addMessage("c2c_" + element.userId, list);
      } else {
        EasyLoading.dismiss();
        showToast("发送失败");
      }
    });
    StringBuffer sp = new StringBuffer();
    userId.forEach((element) {
      sp.write(element + ",");
    });
    var result = await SaveSomeMessageDao.saveSomeMessage(
        context: value,
        contextType: 1,
        receiver: widget.someUser.length,
        toUsers: sp,
        userId: userIdS);
    if (result['resultCode'] == 1) {
      Get.back(result: 'true');
    } else {
      showToast("保存失败");
    }
  }

  String userIdS;

  /// 加载当前登录用户信息
  _loadUserInfo() async {
    await TencentImSDKPlugin.v2TIMManager.getLoginUser().then((value) async {
      await TencentImSDKPlugin.v2TIMManager
          .getUsersInfo(userIDList: [value.data]).then((values) {
        userIdS = values.data[0].userID;
      });
    });
  }

  ScrollController _controller = new ScrollController();
  bool flagBootom = true;
  List<V2TimMessage> someMessage = [];
  bool value = false;
  bool checkMessage = true;
  List<Widget> name;
  getNames() {
    name = [];
    widget.someUser.forEach((element) {
      name.add(Text(
        element.name + ",",
        style:
            TextStyle(fontSize: 13.sp, color: ZdColor.rgba(153, 153, 153, 1)),
      ));
    });
  }

  @override
  Widget build(BuildContext context) {
    // return Scaffold(
    //   body: Center(
    //     child: Text("asd"),
    //   ),
    // );

    return Scaffold(
      backgroundColor: Colors.white,
      appBar: AppBar(
        leading: InkWell(
          onTap: () {
            if (checkMessage) {
              Get.back(result: 'true');
            } else {
              setState(() {
                checkMessage = true;
              });
            }
          },
          child: checkMessage
              ? Icon(Icons.arrow_back_ios)
              : Container(
                  alignment: Alignment.center,
                  child: Text(
                    "取消",
                    textAlign: TextAlign.center,
                    style: TextStyle(fontSize: 15.sp),
                  ),
                ),
        ),
        title: Text("群发助手"),
        centerTitle: true,
        elevation: 0,
      ),
      body: GestureDetector(
        onTap: () {
          FocusScope.of(context).requestFocus(FocusNode());
        },
        child: Container(
          //todo 聊天背景图 备用
          // decoration: BoxDecoration(image: DecorationImage(
          //   image:
          // )),
          color: ZdColor.rgba(237, 237, 237, 1),
          child: Column(
            children: [
              Expanded(
                child: Column(
                  children: [
                    Container(
                      color: ZdColor.rgba(249, 249, 249, 1),
                      child: Column(
                        children: [
                          Container(
                            child: Text(
                              "你将发送消息给" +
                                  widget.someUser.length.toString() +
                                  "位朋友：",
                              style: TextStyle(
                                  fontSize: 13.sp,
                                  color: ZdColor.rgba(153, 153, 153, 1)),
                            ),
                            alignment: Alignment.centerLeft,
                          ),
                          Container(
                            child: Wrap(
                              children: name,
                            ),
                            alignment: Alignment.centerLeft,
                          ),
                        ],
                      ),
                      padding: EdgeInsets.only(left: 16.w, top: 16),
                      width: double.infinity,
                      height: 80,
                    ),
                  ],
                ),
              ),
              Container(
                color: checkMessage
                    ? ZdColor.rgba(246, 246, 246, 1)
                    : Colors.white,
                child: Padding(
                  padding: const EdgeInsets.all(8.0),
                  child: Row(
                    mainAxisAlignment: MainAxisAlignment.center,
                    crossAxisAlignment: CrossAxisAlignment.center,
                    children: [
                      checkMessage ? Container(width: width(4)) : SizedBox(),
                      checkMessage
                          ? InkWell(
                              onTap: () {
                                setState(() {
                                  soundFlag = !soundFlag;
                                  favorite = true;
                                  emojo = true;
                                  flag = false;
                                  flagBootom = true;
                                  bottomIcon = "images/message/表情.png";
                                  if (soundFlag) {
                                    leftIcon = "images/message/键盘.png";
                                  } else {
                                    leftIcon = "images/message/语音.png";
                                  }
                                });
                              },
                              child: Container(
                                height: 30,
                                width: width(28),
                                child: Image.asset(
                                  leftIcon,
                                  fit: BoxFit.cover,
                                  height: 22,
                                  width: width(19),
                                ),
                              ),
                            )
                          : SizedBox(),
                      checkMessage ? Container(width: 8) : SizedBox(),
                      checkMessage
                          ? soundFlag
                              ? Expanded(
                                  child: GestureDetector(
                                    onLongPressStart: (e) {
                                      setState(() {
                                        isRecording = true;
                                        isSend = true;
                                      });
                                      print("anxia ");
                                      buildOverLayView(context);
                                      _requestAppDocumentsDirectory();
                                    },
                                    onLongPressEnd: (e) {
                                      bool isSendLocal = true;
                                      if (e.localPosition.dx < 0 ||
                                          e.localPosition.dy < 0 ||
                                          e.localPosition.dy > 40) {
                                        print("滑动");
                                        isSendLocal = false;

                                        flags = false;
                                        showToast("取消发送");
                                        try {
                                          if (overlayEntry != null) {
                                            overlayEntry.remove();
                                            overlayEntry = null;
                                          }
                                        } catch (err) {}
                                        setState(() {
                                          isRecording = true;
                                          isSend = true;
                                        });
                                        stop();
                                      } else {
                                        try {
                                          if (overlayEntry != null) {
                                            overlayEntry.remove();
                                            overlayEntry = null;
                                          }
                                        } catch (err) {}
                                        setState(() {
                                          isRecording = true;
                                          isSend = true;
                                          flags = true;
                                        });

                                        stop();
                                      }
                                    },
                                    child: Container(
                                        width: width(250),
                                        constraints: BoxConstraints(
                                          maxHeight: 40,
                                        ),
                                        decoration: BoxDecoration(
                                          borderRadius: BorderRadius.all(
                                              Radius.circular(6)),
                                          color: Colors.white,
                                        ),
                                        alignment: Alignment.center,
                                        child: Text("按下发送")),
                                  ),
                                )
                              : Expanded(
                                  child: Container(
                                    width: width(250),
                                    constraints: BoxConstraints(
                                      maxHeight: 40,
                                    ),
                                    decoration: BoxDecoration(
                                      borderRadius:
                                          BorderRadius.all(Radius.circular(6)),
                                      color: Colors.white,
                                    ),
                                    child: TextField(
                                      cursorColor: Colors.greenAccent,
                                      onSubmitted: (value) {
                                        print(
                                            "onSubmitted 点击了键盘的确定按钮，输出的信息是：${value}");
                                        _sendMessage(value);
                                        FocusScope.of(context)
                                            .requestFocus(_focusNode);
                                      },
                                      controller: _textEditingController,
                                      focusNode: _focusNode,
                                      autofocus: false,
                                      textInputAction: TextInputAction.send,
                                      decoration: InputDecoration(
                                        border: InputBorder.none,
                                        contentPadding: EdgeInsets.only(
                                          left: 15,
                                          top: -8,
                                          bottom: 0,
                                          right: 15,
                                        ),
                                      ),
                                    ),
                                  ),
                                )
                          : Expanded(
                              child: Container(
                                padding: EdgeInsets.only(left: 50),
                                child: Row(
                                  mainAxisAlignment:
                                      MainAxisAlignment.spaceEvenly,
                                  crossAxisAlignment: CrossAxisAlignment.center,
                                  children: [
                                    InkWell(
                                      onTap: () async {
                                        List list = [];

                                        if (someMessage.length > 0) {
                                          someMessage.forEach((element) async {
                                            if (element.elemType == 1) {
                                              list.add(json.encode({
                                                "msgId": element.msgID,
                                                "roomJid": "0",
                                                "type": "5",
                                                "msg": element.textElem.text
                                              }));
                                            } else if (element.elemType == 3) {
                                              //图片
                                              list.add(json.encode({
                                                "msgId": element.msgID,
                                                "roomJid": "1",
                                                "type": "1",
                                                "url": element
                                                    .imageElem.imageList[0].url,
                                                "msg": element
                                                    .imageElem.imageList[0].url
                                              }));
                                            } else if (element.elemType == 4) {
                                              //音频
                                              list.add(json.encode({
                                                "msgId": element.msgID,
                                                "roomJid": "1",
                                                "type": "4",
                                                "url": element.soundElem.url,
                                                "msg": element.soundElem.url,
                                                "fileLength": element
                                                    .soundElem.duration
                                                    .toString()
                                              }));
                                            } else if (element.elemType == 5) {
                                              //视频
                                              list.add(json.encode({
                                                "msgId": element.msgID,
                                                "roomJid": "1",
                                                "type": "2",
                                                "url": element
                                                    .videoElem.snapshotUrl,
                                                "msg":
                                                    element.videoElem.videoUrl,
                                                "fileLength": element
                                                    .videoElem.duration
                                                    .toString()
                                              }));

                                              json.encode(list);
                                            }
                                          });
                                          await CollectDao.addCollect(
                                              "", "", "",
                                              roomJid: "",
                                              emoji: list.toString());
                                        } else {
                                          showToast("至少要选中一条消息");
                                        }
                                      },
                                      child: Container(
                                          width: width(100),
                                          height: 40,
                                          decoration: BoxDecoration(
                                            borderRadius: BorderRadius.all(
                                                Radius.circular(6)),
                                            color: Colors.white,
                                          ),
                                          child: Text(
                                            "收藏",
                                            style: TextStyle(fontSize: 15.sp),
                                          )),
                                    ),
                                    InkWell(
                                      onTap: () {
                                        if (someMessage.length > 0) {
                                          Get.to(GetContactsWidget(
                                              someMessage: someMessage));
                                        } else {
                                          showToast("至少要选中一条消息");
                                        }
                                      },
                                      child: Container(
                                          width: width(100),
                                          height: 40,
                                          decoration: BoxDecoration(
                                            borderRadius: BorderRadius.all(
                                                Radius.circular(6)),
                                            color: Colors.white,
                                          ),
                                          child: Text(
                                            "转发",
                                            style: TextStyle(fontSize: 15.sp),
                                          )),
                                    ),
                                    InkWell(
                                      onTap: () {},
                                      child: Container(
                                          width: width(100),
                                          height: 40,
                                          decoration: BoxDecoration(
                                            borderRadius: BorderRadius.all(
                                                Radius.circular(6)),
                                            color: Colors.white,
                                          ),
                                          child: Text(
                                            "删除",
                                            style: TextStyle(fontSize: 15.sp),
                                          )),
                                    ),
                                  ],
                                ),
                              ),
                            ),
                      checkMessage ? Container(width: 8) : SizedBox(),
                      checkMessage
                          ? InkWell(
                              onTap: () {
                                setState(() {
                                  if (_focusNode.hasFocus || flag) {
                                    _focusNode.unfocus();
                                    flag = false;
                                    flagBootom = false;
                                    showToast("images/message/键盘.png");

                                    setState(() {
                                      emojo = false;
                                      bottomIcon = "images/message/键盘.png";
                                      leftIcon = "images/message/语音.png";
                                      soundFlag = false;
                                    });
                                  } else {
                                    if (!emojo) {
                                      // showToast("1");

                                      emojo = true;
                                      bottomIcon = "images/message/表情.png";
                                    } else if (emojo) {
                                      //showToast("2");
                                      emojo = false;
                                      soundFlag = false;
                                      leftIcon = "images/message/语音.png";
                                      bottomIcon = "images/message/键盘.png";
                                    }
                                    flagBootom = true;

                                    favorite = true;
                                    flag = false;
                                    setState(() {});
                                  }
                                });
                              },
                              child: Container(
                                height: 30,
                                width: width(28),
                                child: Image.asset(
                                  bottomIcon,
                                  fit: BoxFit.cover,
                                  height: width(22),
                                  width: width(22),
                                ),
                              ),
                            )
                          : SizedBox(),
                      checkMessage
                          ? SizedBox(
                              width: width(10),
                            )
                          : SizedBox(),
                      checkMessage
                          ? InkWell(
                              onTap: () {
                                if (!emojo) {
                                  setState(() {
                                    emojo = true;
                                  });
                                }
                                setState(() {
                                  flag = !flag;
                                  favorite = true;
                                  soundFlag = false;
                                  leftIcon = "images/message/语音.png";
                                  bottomIcon = "images/message/表情.png";
                                  _focusNode.unfocus();
                                });
                              },
                              child: Container(
                                height: 30,
                                width: width(28),
                                child: Image.asset(
                                  "images/增加.png",
                                  fit: BoxFit.cover,
                                  height: width(22),
                                  width: width(22),
                                ),
                              ),
                            )
                          : SizedBox(),
                    ],
                  ),
                ),
              ),
              flag
                  ? Container(
                      height: 257,
                      color: ZdColor.rgba(237, 237, 237, 1),
                      child: Column(
                        children: [
                          Row(
                            mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                            children: [
                              Column(
                                children: [
                                  InkWell(
                                    onTap: () {
                                      _imagesSelect();
                                      showToast("暂不可用");
                                    },
                                    child: Container(
                                      margin: EdgeInsets.only(
                                        top: 20,
                                      ),
                                      alignment: Alignment.center,
                                      decoration: BoxDecoration(
                                        borderRadius: BorderRadius.circular(10),
                                        color: Colors.white,
                                      ),
                                      height: width(60),
                                      width: width(60),
                                      child: Image.asset(
                                        "images/message/picture_fill.png",
                                        height: width(23),
                                        width: width(23),
                                      ),
                                    ),
                                  ),
                                  Container(
                                    alignment: Alignment.center,
                                    margin: EdgeInsets.only(top: 5),
                                    child: Text(
                                      "照片",
                                      style: TextStyle(
                                          fontSize: sp(12),
                                          color: ZdColor.rgba(85, 85, 85, 1)),
                                    ),
                                  )
                                ],
                              ),
                              Column(
                                children: [
                                  InkWell(
                                    onTap: _photoSelect,
                                    child: Container(
                                      margin: EdgeInsets.only(
                                        top: 20,
                                      ),
                                      alignment: Alignment.center,
                                      decoration: BoxDecoration(
                                        borderRadius: BorderRadius.circular(10),
                                        color: Colors.white,
                                      ),
                                      height: width(60),
                                      width: width(60),
                                      child: Image.asset(
                                        "images/message/camera_fill.png",
                                        height: width(23),
                                        width: width(23),
                                      ),
                                    ),
                                  ),
                                  Container(
                                    alignment: Alignment.center,
                                    margin: EdgeInsets.only(top: 5),
                                    child: Text(
                                      "拍照",
                                      style: TextStyle(
                                          fontSize: sp(12),
                                          color: ZdColor.rgba(85, 85, 85, 1)),
                                    ),
                                  )
                                ],
                              ),
                              Column(
                                children: [
                                  InkWell(
                                    onTap: () async {
                                      //showToast("暂未开放");
                                      await _videoSelect();
                                    },
                                    child: Container(
                                      margin: EdgeInsets.only(
                                        top: 20,
                                      ),
                                      alignment: Alignment.center,
                                      decoration: BoxDecoration(
                                        borderRadius: BorderRadius.circular(10),
                                        color: Colors.white,
                                      ),
                                      height: width(60),
                                      width: width(60),
                                      child: Image.asset(
                                        "images/message/video_fill.png",
                                        height: width(23),
                                        width: width(23),
                                      ),
                                    ),
                                  ),
                                  Container(
                                    alignment: Alignment.center,
                                    margin: EdgeInsets.only(top: 5),
                                    child: Text(
                                      "视频",
                                      style: TextStyle(
                                          fontSize: sp(12),
                                          color: ZdColor.rgba(85, 85, 85, 1)),
                                    ),
                                  )
                                ],
                              ),

                              //TODO 暂时隐藏
                              // Column(
                              //   children: [
                              //     Container(
                              //       margin: EdgeInsets.only(
                              //         top: 20,
                              //       ),
                              //       alignment: Alignment.center,
                              //       decoration: BoxDecoration(
                              //         borderRadius: BorderRadius.circular(10),
                              //         color: Colors.white,
                              //       ),
                              //       height: width(60),
                              //       width: width(60),
                              //       child: Image.asset(
                              //         "images/message/语音.png",
                              //         height: width(23),
                              //         width: width(23),
                              //       ),
                              //     ),
                              //     Container(
                              //       alignment: Alignment.center,
                              //       margin: EdgeInsets.only(top: 5),
                              //       child: Text(
                              //         "语音通话",
                              //         style: TextStyle(
                              //             fontSize: sp(12),
                              //             color: ZdColor.rgba(85, 85, 85, 1)),
                              //       ),
                              //     )
                              //   ],
                              // ),
                              Column(
                                children: [
                                  InkWell(
                                    onTap: () {
                                      _openModalBottomSheet();
                                    },
                                    child: Container(
                                      margin: EdgeInsets.only(
                                        top: 20,
                                      ),
                                      alignment: Alignment.center,
                                      decoration: BoxDecoration(
                                        borderRadius: BorderRadius.circular(10),
                                        color: Colors.white,
                                      ),
                                      height: width(60),
                                      width: width(60),
                                      child: Image.asset(
                                        "images/message/barrage_fill.png",
                                        height: width(23),
                                        width: width(23),
                                      ),
                                    ),
                                  ),
                                  InkWell(
                                    onTap: () {},
                                    child: Container(
                                      alignment: Alignment.center,
                                      margin: EdgeInsets.only(top: 5),
                                      child: Text(
                                        "常用语",
                                        style: TextStyle(
                                            fontSize: sp(12),
                                            color: ZdColor.rgba(85, 85, 85, 1)),
                                      ),
                                    ),
                                  )
                                ],
                              ),
                            ],
                          ),
                          //TODO 暂时隐藏
                          Row(
                            mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                            children: [
                              // Column(
                              //   children: [
                              //     Container(
                              //       margin: EdgeInsets.only(
                              //         top: 20,
                              //       ),
                              //       alignment: Alignment.center,
                              //       decoration: BoxDecoration(
                              //         borderRadius: BorderRadius.circular(10),
                              //         color: Colors.white,
                              //       ),
                              //       height: width(60),
                              //       width: width(60),
                              //       child: Image.asset(
                              //         "images/message/coordinates_fill.png",
                              //         height: width(23),
                              //         width: width(23),
                              //       ),
                              //     ),
                              //     Container(
                              //       alignment: Alignment.center,
                              //       margin: EdgeInsets.only(top: 5),
                              //       child: Text(
                              //         "位置",
                              //         style: TextStyle(
                              //             fontSize: sp(12),
                              //             color: ZdColor.rgba(85, 85, 85, 1)),
                              //       ),
                              //     )
                              //   ],
                              // ),
                              // Column(
                              //   children: [
                              //     Container(
                              //       margin: EdgeInsets.only(
                              //         top: 20,
                              //       ),
                              //       alignment: Alignment.center,
                              //       decoration: BoxDecoration(
                              //         borderRadius: BorderRadius.circular(10),
                              //         color: Colors.white,
                              //       ),
                              //       height: width(60),
                              //       width: width(60),
                              //       child: Image.asset(
                              //         "images/message/tasklist_fill.png",
                              //         height: width(23),
                              //         width: width(23),
                              //       ),
                              //     ),
                              //     Container(
                              //       alignment: Alignment.center,
                              //       margin: EdgeInsets.only(top: 5),
                              //       child: Text(
                              //         "文件",
                              //         style: TextStyle(
                              //             fontSize: sp(12),
                              //             color: ZdColor.rgba(85, 85, 85, 1)),
                              //       ),
                              //     )
                              //   ],
                              // ),

                              Column(
                                children: [
                                  InkWell(
                                    onTap: () {
                                      Get.to(() => CollectPage());
                                    },
                                    child: Container(
                                      margin: EdgeInsets.only(
                                        top: 20,
                                      ),
                                      alignment: Alignment.center,
                                      decoration: BoxDecoration(
                                        borderRadius: BorderRadius.circular(10),
                                        color: Colors.white,
                                      ),
                                      height: width(60),
                                      width: width(60),
                                      child: Image.asset(
                                        "images/message/manage_fill.png",
                                        height: width(23),
                                        width: width(23),
                                      ),
                                    ),
                                  ),
                                  Container(
                                    alignment: Alignment.center,
                                    margin: EdgeInsets.only(top: 5),
                                    child: Text(
                                      "我的收藏",
                                      style: TextStyle(
                                          fontSize: sp(12),
                                          color: ZdColor.rgba(85, 85, 85, 1)),
                                    ),
                                  )
                                ],
                              ),
                              SizedBox(
                                width: 60.w,
                              ),
                              SizedBox(
                                width: 60.w,
                              ),
                              SizedBox(
                                width: 60.w,
                              ),
                            ],
                          ),
                        ],
                      ),
                    )
                  : SizedBox(),
              Offstage(
                offstage: emojo,
                child: Column(
                  children: [
                    Container(
                      height: 260,
                      child: EmojiPicker(
                          onEmojiSelected: (Category category, Emoji emoji) {
                            _onEmojiSelected(emoji);
                          },
                          onBackspacePressed: _onBackspacePressed,
                          config: const Config(
                              columns: 7,
                              emojiSizeMax: 32.0,
                              verticalSpacing: 0,
                              horizontalSpacing: 0,
                              initCategory: Category.RECENT,
                              bgColor: Color(0xFFF2F2F2),
                              indicatorColor: Colors.blue,
                              iconColor: Colors.grey,
                              iconColorSelected: Colors.blue,
                              progressIndicatorColor: Colors.blue,
                              backspaceColor: Colors.blue,
                              showRecentsTab: true,
                              recentsLimit: 28,
                              noRecentsText: 'No Recents',
                              noRecentsStyle: TextStyle(
                                  fontSize: 20, color: Colors.black26),
                              categoryIcons: CategoryIcons(),
                              buttonMode: ButtonMode.MATERIAL)),
                    ),
                    Container(
                      margin: EdgeInsets.only(left: 20.w),
                      child: Row(
                        children: [
                          InkWell(
                            child: Container(
                              height: 40.w,
                              width: 40.w,
                              padding: EdgeInsets.all(10),
                              child: Image.asset(
                                "images/message/表情.png",
                                height: 22.w,
                                width: 22.w,
                              ),
                              decoration: BoxDecoration(
                                borderRadius: BorderRadius.circular(6),
                                color: !emojo ? white : null,
                              ),
                            ),
                            onTap: () {
                              setState(() {
                                emojo = false;
                              });
                            },
                          ),
                          InkWell(
                            onTap: () {
                              setState(() {
                                favorite = false;
                                //收藏 按键
                                getData();
                                emojo = true;
                              });
                            },
                            child: Container(
                                margin: EdgeInsets.only(left: width(10)),
                                decoration: BoxDecoration(
                                  borderRadius: BorderRadius.circular(6),
                                  color: !favorite ? white : null,
                                ),
                                height: 40.w,
                                width: 40.w,
                                alignment: Alignment.center,
                                child: Icon(Icons.favorite_outline_rounded)),
                          ),
                          InkWell(
                            onTap: () {
                              _sendMessage(_textEditingController != null
                                  ? _textEditingController.text != null &&
                                          _textEditingController.text != ""
                                      ? _textEditingController.text
                                      : ""
                                  : "");
                            },
                            child: Container(
                              alignment: Alignment.center,
                              margin: EdgeInsets.only(
                                  top: 11, bottom: 11, right: 15, left: 167.w),
                              height: 38,
                              width: ScreenUtil().setWidth(60),
                              decoration: BoxDecoration(
                                borderRadius: BorderRadius.circular(6),
                                color: Color.fromRGBO(0, 220, 169, 1),
                              ),
                              child: Text(
                                "发送",
                                style: TextStyle(
                                    color: Colors.white,
                                    fontSize: ScreenUtil().setSp(14)),
                              ),
                            ),
                          )
                        ],
                      ),
                    ),
                  ],
                ),
              ),
              Offstage(
                offstage: favorite,
                child: Container(
                    child: Column(
                  children: [
                    Container(
                      height: 260,
                      width: double.infinity,
                      child: ListView(
                        shrinkWrap: true,
                        children: [
                          Wrap(
                            children: widgetData,
                          )
                        ],
                      ),
                    ),
                    Container(
                      margin: EdgeInsets.only(left: 20.w),
                      child: Row(
                        children: [
                          InkWell(
                            child: Container(
                              height: 40.w,
                              width: 40.w,
                              padding: EdgeInsets.all(10),
                              child: Image.asset(
                                "images/message/表情.png",
                                height: 22.w,
                                width: 22.w,
                              ),
                              decoration: BoxDecoration(
                                borderRadius: BorderRadius.circular(6),
                                color: !emojo ? white : null,
                              ),
                            ),
                            onTap: () {
                              setState(() {
                                favorite = true;
                                emojo = false;
                              });
                            },
                          ),
                          InkWell(
                            onTap: () {
                              setState(() {
                                favorite = true;
                                emojo = true;
                              });
                            },
                            child: Container(
                                margin: EdgeInsets.only(left: width(10)),
                                decoration: BoxDecoration(
                                  borderRadius: BorderRadius.circular(6),
                                  color: !favorite ? white : null,
                                ),
                                height: 40.w,
                                width: 40.w,
                                alignment: Alignment.center,
                                child: Icon(Icons.favorite_outline_rounded)),
                          ),
                          InkWell(
                            onTap: () {
                              _sendMessage(_textEditingController != null
                                  ? _textEditingController.text != null &&
                                          _textEditingController.text != ""
                                      ? _textEditingController.text
                                      : ""
                                  : "");
                            },
                            child: Container(
                              alignment: Alignment.center,
                              margin: EdgeInsets.only(
                                  top: 11, bottom: 11, right: 15, left: 167.w),
                              height: 38,
                              width: ScreenUtil().setWidth(60),
                              decoration: BoxDecoration(
                                borderRadius: BorderRadius.circular(6),
                                color: Color.fromRGBO(0, 220, 169, 1),
                              ),
                              child: Text(
                                "发送",
                                style: TextStyle(
                                    color: Colors.white,
                                    fontSize: ScreenUtil().setSp(14)),
                              ),
                            ),
                          )
                        ],
                      ),
                    ),
                  ],
                )),
              ),
              !checkMessage
                  ? Container(
                      color: Colors.white,
                      height: MediaQuery.of(context).padding.bottom,
                    )
                  : Container(
                      color: flag == true ||
                              checkMessage == false ||
                              favorite == false ||
                              emojo == false
                          ? null
                          : ZdColor.rgba(246, 246, 246, 1),
                      height: MediaQuery.of(context).padding.bottom,
                    )
            ],
          ),

          ///
        ),
      ),
    );
  }

  String leftIcon = "images/message/语音.png";
  List<Widget> widgetElse = [];
  List<Widget> widgetData = [];
  List emojiId = [];
  bool a = false;
  getData() async {
    widgetData = [];
    widgetData.add(InkWell(
      onTap: () {
        setState(() {
          emojo = true;
          favorite = true;
          flag = false;
          bottomIcon = "images/message/表情.png";
          leftIcon = "images/message/语音.png";
          soundFlag = false;
        });
        Get.to(() => MessageIconPage());
      },
      child: Container(
        height: 55.w,
        width: 55.w,
        margin: EdgeInsets.only(left: 18.w, top: 15),
        decoration: BoxDecoration(
            borderRadius: BorderRadius.circular(6),
            border: Border.all(
                width: 1,
                color: ZdColor.rgba(153, 153, 153, 1),
                style: BorderStyle.solid)),
        child: Icon(
          Icons.add,
          color: ZdColor.rgba(153, 153, 153, 1),
        ),
      ),
    ));
    CollectListModel collectListModel =
        await EmojiListDao.getEmojiList(getUserInfo().userId);
    if (collectListModel.resultCode == 1) {
      collectListModel.data.forEach((element) {});
    }
    setState(() {});
  }

  Future _openModalBottomSheet() async {
    await getDataList();
    print(1);
    final option = await showModalBottomSheet(
        context: context,
        builder: (BuildContext context) {
          return Container(
            height: 460.0,
            child: Column(
              children: <Widget>[
                ListTile(
                  leading: InkWell(
                    onTap: () {
                      Navigator.pop(context, '常用语');
                      Get.to(() => CommonLanguagePage(3));
                    },
                    child: Container(
                      height: 40,
                      width: 40,
                      child: Icon(
                        Icons.add_circle_outline,
                        size: 20,
                      ),
                    ),
                  ),
                  title: Text(
                    '常用语',
                    textAlign: TextAlign.center,
                    style: TextStyle(
                        fontSize: 18.sp, color: ZdColor.rgba(51, 51, 51, 1)),
                  ),
                  onTap: () {
                    //_photoSelect();
                    Navigator.pop(context, '常用语');
                  },
                  trailing: InkWell(
                    onTap: () {
                      //_photoSelect();
                      Navigator.pop(context, '常用语');
                    },
                    child: Icon(
                      Icons.clear,
                      size: 20,
                    ),
                  ),
                ),
                Divider(
                  height: 1,
                  indent: ScreenUtil().setWidth(10),
                  color: Color.fromRGBO(248, 248, 248, 1),
                  thickness: ScreenUtil().setHeight(1),
                ),
                Expanded(
                  child: ListView(
                    children: sheetList,
                  ),
                ),
              ],
            ),
          );
        });
    print(option);
  }

  bool favorite = true;
  List<Widget> sheetList = [];
  List<CommonLanguageBean> _lists = [];
  getDataList() async {
    sheetList = [];
    print('userId:${getUserInfo().userId}');
    _lists.clear();
    LinkedHashMap hashMap = await CommonLanguageDao.getData(3);
    if (!hashMap.containsKey("data")) {
      return;
    }
    CommonLanguageModel commonLanguageModel =
        CommonLanguageModel.fromJson(hashMap);

    if (mounted)
      setState(() {
        _lists.addAll(commonLanguageModel.data);
      });
    if (_lists.length > 0) {
      _lists.forEach((element) {
        sheetList.add(
          ListTile(
            title: Text(
              element.context ?? "",
              textAlign: TextAlign.left,
              style: TextStyle(
                fontSize: 15.sp,
              ),
            ),
            onTap: () {
              getDataList();
              _sendMessage(element.context ?? "123");
              Navigator.pop(context, '取消');
              // _imagesSelect();
            },
          ),
        );
        sheetList.add(
          Divider(
            height: 1,
            indent: 15.w,
            color: ZdColor.rgba(245, 245, 245, 1),
            thickness: 1.w,
            endIndent: 15.w,
          ),
        );
      });
    }
  }

  bool emojo = true;

  final TextEditingController _controllers = TextEditingController();
  _onEmojiSelected(Emoji emoji) {
    _textEditingController
      ..text += emoji.emoji
      ..selection = TextSelection.fromPosition(
          TextPosition(offset: _textEditingController.text.length));
  }

  _onBackspacePressed() {
    _textEditingController
      ..text = _textEditingController.text.characters.skipLast(1).toString()
      ..selection = TextSelection.fromPosition(
          TextPosition(offset: _textEditingController.text.length));
  }

  @override
  // TODO: implement wantKeepAlive
  bool get wantKeepAlive => true;
}
